// Koa 项目学习
// koa-router的动态路由
let Koa = require('koa') //引入koa
let router = require('koa-router')() //引入koa-router并且实例化

let app = new Koa() // 实例化

router.get('/', async (ctx) => {
  ctx.body = "this is index page"
})

router.get('/news', async (ctx) => {
  ctx.body = "this is news page"
})

// 配置动态路由
// localhost:3000/aid
router.get('/detail/:aid', async (ctx) => {
  let params = ctx.params // 获取动态路由的传值
  console.log(params)
  ctx.body = "this is detail page"
})
// 配置动态路由，动态路由可以传多个值
// localhost:3000/aid/name
router.get('/content/:aid/:name', async (ctx) => {
  let params = ctx.params // 获取动态路由的传值
  console.log(params)
  ctx.body = "this is detail page"
})

app.use(router.routes()) //启动路由
app.use(router.allowedMethods()) //建议配置，可以配置，也可以不配置

app.listen(3000) // 监听端口